package com.hopes.bizz.enforcement.hid.vo;

import com.hopes.bizz.common.core.util.DateUtils;
import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.enforcement.common.constant.enums.EnforcementSysDictEnum;
import com.hopes.bizz.enforcement.hid.entity.RiskHidCheckContentConfigEntity;
import com.hopes.bizz.enforcement.hid.entity.RiskHidCheckTaskEntity;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.common.entity.BaseLogicEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/7/28 11:13
 * @Description:
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Schema(description = "隐患检查任务VO")
public class RiskHidCheckTaskVO extends BaseLogicEntity {

    private static final long serialVersionUID = -1274235389643233886L;

    public RiskHidCheckTaskVO(RiskHidCheckTaskEntity riskHidCheckTaskEntity) {
        this.id = riskHidCheckTaskEntity.getId();
        this.planId = riskHidCheckTaskEntity.getPlanId();
        this.hidCheckListConfigId = riskHidCheckTaskEntity.getHidCheckListConfigId();
        this.checkObject = riskHidCheckTaskEntity.getCheckObject();
        this.checkPerson = riskHidCheckTaskEntity.getCheckPerson();
        this.taskNo = riskHidCheckTaskEntity.getTaskNo();
        this.handleId = riskHidCheckTaskEntity.getHandleId();
        this.taskName = riskHidCheckTaskEntity.getTaskName();
        this.taskStatus = riskHidCheckTaskEntity.getTaskStatus();
        this.taskConclusion = riskHidCheckTaskEntity.getTaskConclusion();
        this.startTime = riskHidCheckTaskEntity.getStartTime();
        this.deadline = riskHidCheckTaskEntity.getDeadline();
        this.passNum = riskHidCheckTaskEntity.getPassNum();
        this.notPassNum = riskHidCheckTaskEntity.getNotPassNum();
        this.totalNum = riskHidCheckTaskEntity.getTotalNum();
        this.finishDate = riskHidCheckTaskEntity.getFinishDate();
        this.checkPersonSignature = riskHidCheckTaskEntity.getCheckPersonSignature();
        this.recorderSignature = riskHidCheckTaskEntity.getRecorderSignature();
        this.orgId = riskHidCheckTaskEntity.getOrgId();
    }

    private Long id;

    private Long planId;

    private String hidCheckListConfigId;

    @Schema(description="受检对象")
    private String checkObject;

    @Schema(description="检查人")
    private String checkPerson;

    @Schema(description="任务编号")
    private String taskNo;

    @Schema(description="处理人")
    private Long handleId;

    @Schema(description="任务名称")
    private String taskName;

    @Schema(description="任务状态")
    private Integer taskStatus;

    @Schema(description="任务结论")
    private Integer taskConclusion;

    @Schema(description="开始时间")
    private Date startTime;

    @Schema(description="截止时间")
    private Date deadline;

    @Schema(description="符合项")
    private Integer passNum;

    @Schema(description="不符合项")
    private Integer notPassNum;

    @Schema(description="检查总项")
    private Integer totalNum;

    @Schema(description="完成时间")
    private Date finishDate;

    @Schema(description="排查人签名")
    private String checkPersonSignature;

    @Schema(description="记录人签名")
    private String recorderSignature;

    @Schema(description="机构ID")
    private Long orgId;

    private List<RiskHidCheckContentConfigEntity> contentConfigs;

    public String getDeadlineStr() {
        return DateUtils.limitMinute(this.deadline);
    }

    public String getStartTimeStr() {
        return DateUtils.limitMinute(this.startTime);
    }

    public String getFinishDateStr() {
        return DateUtils.limitMinute(this.finishDate);
    }

    public String getTaskStatusStr() {
        return DictResolver.getItemLabelByValue(EnforcementSysDictEnum.risk_hid_checklist_task_status, this.getTaskStatus());
    }

    public String getTaskConclusionStr() {
        return DictResolver.getItemLabelByValue(EnforcementSysDictEnum.risk_hid_checklist_task_conclusion, this.getTaskConclusion());
    }

    public String getHandleIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getHandleId());
    }


    public String getCheckPersonStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getCheckPerson());
    }

    public List<Long> getHidCheckListConfigIdList() {
        List<Long> deptList = new ArrayList<>();
        if (this.hidCheckListConfigId != null) {
            for (String s : this.hidCheckListConfigId.split(StringUtils.COMMA)) {
                deptList.add(Long.parseLong(s));
            }
        }
        return deptList;
    }

}
